package com.ophiux.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ophiux.common.core.base.Result;
import com.ophiux.product.model.dto.ProductDTO;
import com.ophiux.product.model.vo.ProductQueryVo;
import com.ophiux.product.service.impl.ProductServiceImpl;
import com.ophiux.system.api.feign.SysLogFeignApi;
import com.ophiux.system.model.entity.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product")
@Api(tags = "商品接口")
@RefreshScope
public class ProductController {
	
    @Autowired
    ProductServiceImpl productService;


    @ApiOperation("1.列表记录")
    @GetMapping
    public Result<IPage<ProductDTO>> list(@RequestParam(required = false, defaultValue = "1") Integer current,
                                          @RequestParam(required = false, defaultValue = "10") Integer size, ProductQueryVo queryDTO) {
		IPage<ProductDTO> page = productService.getPage(new Page<>(current, size), queryDTO);
		return Result.success(page);
    }
	
    @ApiOperation("扣减库存")
    @GetMapping("/reduceStock")
    public Result reduceStock(@RequestParam("stockNum") Integer stockNum){
	    return productService.updateStock(stockNum,1);
    }

    @Autowired
    private SysLogFeignApi sysLogFeignApi;

    @GetMapping("/test")
    public Result testLog(){
        SysLog sysLog = new SysLog();
        sysLog.setParams("21111");
        sysLogFeignApi.saveLog(sysLog);
        return Result.success();
    }

    public static int coun = 0;

    @Value("${ophiux.name}")
    private String name;
    @GetMapping("/test3")
    @ApiOperation("feign找不到接口")
    public Result test3() {
        System.out.println(name);
        coun = coun + 1;
        sysLogFeignApi.getCountLog();
        return Result.success("成功"+name + coun);
    }

}
